package com.woniuxy.project.campus.canteen.controller;


import cn.hutool.core.bean.BeanUtil;
import com.woniuxy.project.campus.canteen.dto.QueryProductAllDto;
import com.woniuxy.project.campus.canteen.model.ModifyDiscountParam;
import com.woniuxy.project.campus.canteen.model.ProductList;
import com.woniuxy.project.campus.canteen.param.AddProductParam;
import com.woniuxy.project.campus.canteen.param.ModifyPriceParam;
import com.woniuxy.project.campus.canteen.param.ModifyStatusParam;
import com.woniuxy.project.campus.canteen.param.ModifyTypeParam;
import com.woniuxy.project.campus.canteen.service.ProductListService;
import com.woniuxy.project.campus.canteenModelform.*;
import com.woniuxy.project.campus.util.Result;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 猫将军
 * @since 2025年02月17日
 */
@RestController
@RequestMapping("/productList")
public class ProductListController {

    @Resource
    private ProductListService productListService;

    //商户添加商品
    @RequestMapping ("/addProduct")
    public Result addProduct(@RequestHeader("token") String token,  AddProductForm form) throws Exception{
        AddProductParam bean = BeanUtil.toBean(form, AddProductParam.class);
        bean.setToken(token);
        productListService.addProduct(bean);
        return Result.success("添加成功");
    }
    //商户修改商品价格
    @ApiOperation(value = "修改商品价格", notes = "传入商品id 修改后的价格")
    @RequestMapping("/modifyPrice")
    public Result modifyPrice(@RequestHeader("token") String token, @RequestBody ModifyPriceForm form) throws Exception{
        ModifyPriceParam bean = BeanUtil.toBean(form, ModifyPriceParam.class);
        bean.setToken(token);
        productListService.modifyPrice(bean);
        return Result.success("修改成功");
    }
    //商户修改商品状态
    @ApiOperation(value = "修改商品状态", notes = "传入商品id 修改后的商品状态")
    @RequestMapping("/modifyStatus")
    public Result modifyStatus(@RequestHeader("token") String token, @RequestBody ModifyStatusForm form) throws Exception{
        ModifyStatusParam bean = BeanUtil.toBean(form, ModifyStatusParam.class);
        bean.setToken(token);
        productListService.modifyStatus(bean);
        return Result.success("修改成功");
    }
    //商户修改折扣价
    @ApiOperation(value = "修改折扣价", notes = "传入商品id 修改后的折扣价")
    @RequestMapping("/modifyDiscount")
    public Result modifyDiscount(@RequestHeader("token") String token, @RequestBody ModifyDiscountForm form) throws Exception{
        ModifyDiscountParam bean = BeanUtil.toBean(form, ModifyDiscountParam.class);
        bean.setToken(token);
        productListService.modifyDiscount(bean);
        return Result.success("修改成功");
    }
    //用户修改商品类型
    @ApiOperation(value = "修改商品类型", notes = "传入商品id 修改后的商品类型")
    @RequestMapping("/modifyType")
    public Result modifyType(@RequestHeader("token") String token, @RequestBody ModifyTypeForm form) throws Exception{
        ModifyTypeParam bean = BeanUtil.toBean(form, ModifyTypeParam.class);
        bean.setToken(token);
        productListService.modifyType(bean);
        return Result.success("修改成功");
    }

    //用户传入 商铺id 商品id 查询商品详情
    @ApiOperation(value = "查询商品详情", notes = "传入商铺id 商品id")
    @PostMapping("/queryProductDetail")
    public Result queryProductDetail(@RequestBody SelectProShopInfo form) throws Exception{
       ProductList bean = productListService.queryProductDetail(form);
        return Result.success(bean);
    }


    //传入商铺id 查询商品列表
    @ApiOperation(value = "查询商品列表", notes = "传入商铺id")
    @PostMapping("/queryProductList")
    public Result queryProductList( Integer shopId) throws Exception{
        List<ProductList> bean = productListService.queryProductList(shopId);
        return Result.success(bean);
    }

    //传入商品id 查询商品详情
    @ApiOperation(value = "查询商品详情全部信息", notes = "传入商品id")
    @GetMapping("/queryProductDetailById")
    public Result queryProductDetailById(@RequestParam("productId") Integer productId) throws Exception{
        ProductList bean = productListService.queryProductDetailById(productId);
        return Result.success(bean);
    }

    //传入商铺id查询商品老板id
    @ApiOperation(value = "查询商品详情", notes = "传入商铺id")
    @GetMapping("/queryProductDetailByShopId")
    public Result queryProductDetailByShopId(@RequestParam("shopId") Integer shopId) throws Exception{
        Integer bean = productListService.queryProductDetailByShopId(shopId);
        return Result.success(bean);
    }

    //商户查询自己的商品列表
    @GetMapping("/selectProductDetail")
    public Result queryProductDetailByShopId(@RequestHeader("token") String token) throws Exception{
        List<ProductList> bean = productListService.selectProductDetail(token);
        return Result.success(bean);
    }


    @ApiOperation(value = "查询商品详情", notes = "传入商品名称")
    @GetMapping("/selectProductDetailAll")
    public Result queryProductDetailByToken(@RequestParam("productName") String productName) throws Exception{
        List<QueryProductAllDto> bean = productListService.queryProductDetailByToken(productName);
        return Result.success(bean);
    }


    //xing
    @GetMapping("/queryProductNameId")
    Result queryProductNameId(@RequestParam("productId")Integer productId){
        return Result.success(productListService.queryProductNameId(productId));
    }

}

